//
//  RdbGuidePlayController.swift
//  rdb-led-banner
//
//  Created by radiobox3 on 2025/4/18.
//

import UIKit
import SnapKit
import StoreKit

enum RdbGuidePageType: Int{
    case first
    case second
    case third
    case fourth
}

class RdbGuidePlayController: BaseViewController {

    var pageType: RdbGuidePageType = .first
    
    convenience init(type: RdbGuidePageType){
        self.init()
        self.pageType = type
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(textLabel)
        self.textLabel.snp.makeConstraints{
            $0.center.equalToSuperview()
        }
        self.loadData()
    }
    
    func loadData(){
        switch pageType {
        case .first:
            textLabel.text = "first"
        case .second:
            textLabel.text = "second"
        case .third:
            textLabel.text = "third"
        case .fourth:
            textLabel.text = "fourth"
        }
    }
    
    
    private lazy var textLabel: UILabel = {
        let textLabel = UILabel()
        textLabel.textColor = UIColor.white
        textLabel.font = UIFont.bold(22)
        return textLabel
    }()
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if self.pageType == .second {
            self.showScoreView()
        }
    }
    /// 弹出评分
    func showScoreView() {
        if !RdbUserDefaults.boolValue(for: .rdbPopRating){
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return }
            if #available(iOS 14.0, *) {
                SKStoreReviewController.requestReview(in: windowScene)
            } else {
                SKStoreReviewController.requestReview()
            }
            RdbUserDefaults.update(value: true, keyPath: .rdbPopRating)
        }
    }
    

}
